'use strict';

const Service = require('egg').Service;

class ConfigService extends Service {
    async add(name){
       const {ctx,app} = this;
       const res = await ctx.model.Config.findOne({"name":name});
       if(res){
            return Promise.reject(app.resCode.envRepet);
       }else{
        var config = new ctx.model.Config({name});
        return config.save();  
       }
    }
    async remove(id){
        return this.ctx.model.Config.removeOne({"_id":id});
    }
    async update(id,opt){
        return this.ctx.model.Config.updateOne({"_id":id},{"$set":opt});
    }
    async list(){
        return this.ctx.model.Config.find({},{"data":0});
    }
    async info(id){
        return this.ctx.model.Config.findOne({"_id":id});
    }
}

module.exports = ConfigService;